<template>
  <div class="login">
    <div class="login-wrap">
      <el-row type="flex" justify="center">
        <el-form ref="loginForm" :model="user" status-icon label-width="80px">
          <h3>系统管理员登录</h3>
          <hr>
          <el-form-item prop="username" label="用户名">
            <el-input v-model="user.username" placeholder="请输入用户名"></el-input>
          </el-form-item>
          <el-form-item id="password" prop="password" label="密码">
            <el-input v-model="user.password" show-password placeholder="请输入密码"></el-input>
          </el-form-item>
          <br>
          <el-form-item>
            <el-button type="primary" icon="el-icon-upload" @click="doLogin()">登 录</el-button>
          </el-form-item>
        </el-form>
      </el-row>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "root_admin",
  data() {
    return {
      user: {
        username: "",
        password: ""
      }
    };
  },
  created :{

  },
  methods: {
    doLogin() {
      if (!this.user.username) {
        this.$message.error("请输入用户名！");
        return false;
      } else if (!this.user.password) {
        this.$message.error("请输入密码！");
        return false;
      } else {
        //校验用户名和密码是否正确;
        // this.$router.push({ path: "/personal" });
        axios
            .post("/login-service/root/login/", {
              username: this.user.username,
              password: this.user.password
            })
            .then(res => {
              console.log("输出response.data.status", res.data.data);
              if (res.data.flag) {
                window.sessionStorage.setItem("token", res.data.data.id)
                this.$router.push({ path: "/root_index/root_adminadd" });
              } else {

                alert("您输入的用户名或密码错误！");
              }

            });
      }
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.login {
  width: 100%;
  height: 730px;
  background: url("/public/bg.jpg") no-repeat;
  background-size: cover;
  overflow: hidden;
}
.login-wrap {
  background-color: rgba(255, 255, 255, 0.8);
  background-size: cover;
  width: 500px;
  height: 500px;
  /*  margin: 150px auto;*/
  margin-left: 140px;
  margin-top: 120px;
  overflow: hidden;
  padding-top: 20px;
  line-height: 40px;
}
#password {
  margin-bottom: 5px;
}
h3 {
  color: #0babeab8;
  font-size: 24px;
}
hr {
  background-color: #444;
  margin: 20px auto;
}
a {
  text-decoration: none;
  color: #aaa;
  font-size: 15px;
}
a:hover {
  color: coral;
}
.el-button {
  width: 80%;
  margin-left: -50px;
}
</style>